import axios, { AxiosRequestConfig } from "axios";
import { infoStore } from "./store/info";
export const $ = axios.create({
  // baseURL: "http://10.12.115.69:8085",
  // baseURL: "http://127.0.0.1:3000",
  timeout: 1000,
});
$.interceptors.request.use(
  (config) => {
    // post请求的参数在data中
    // if (config.data) config.data.params.token = "test";
    // else config.params.token = "test";
    // console.log(config);
    return config;
  },
  (err) => {
    console.error({ message: "请求超时!" });
    return Promise.resolve(err);
  }
);

import { modal } from "vxe-table";
$.interceptors.response.use(
  (response) => {
    if (response.status === 200) {
      // info.setVerify({ verify: response.data?.data?.verify });
      return Promise.resolve(response);
    } else {
      modal.message({ content: "请求失败", status: "error" });
      //  请求失败返回
      
        const info = infoStore();
        axios
          .get("/oa/saas/perssion.do")
          .then(({ data }) => {
            info.setVerify({ verify: data?.data?.verify });

          })
          .catch(() => {
            info.setVerify({ verify: 0 });
          });
      
      return Promise.reject(response);
    }
  },
  (err) => {
    modal.message({ content: "请求失败", status: "error" });
      //  请求失败返回
      
        const info = infoStore();
        axios
          .get("/oa/saas/perssion.do")
          .then(({ data }) => {
            info.setVerify({ verify: data?.data?.verify });

          })
          .catch(() => {
            info.setVerify({ verify: 0 });
          });
    console.log(err);
    return Promise.reject(err.response);
  }
);
